package cn.wqk.demo.service.impl;

import cn.wqk.demo.mapper.UserMapper;
import cn.wqk.demo.pojo.User;
import cn.wqk.demo.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 吴青珂
 * @Date: 2020/12/25/11:36
 * @Description:
 */
@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    UserMapper userMapper;

    @Override
    public User checkLogin(String username, String password) throws RuntimeException {
        User userDB = userMapper.selectUserByUsernameAndPassword(username,password);
        if (userDB!=null){ // 用户存在，返回查询到的用户信息
            return userDB;
        }
        throw new RuntimeException("认证失败，请重新登录！"); //用户不存在，抛出异常
    }
}
